package com.ctshk.rpc.order.custom.mapper;



import com.ctshk.rpc.order.custom.base.CustomBaseMapper;
import com.ctshk.rpc.order.custom.dto.order.OrderTouristPriceDTO;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderTouristPrice;
import com.ctshk.rpc.order.custom.vo.TouristTypeNum;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 定制包团订单游客自由报价 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
public interface CustomizedOrderTouristPriceMapper extends CustomBaseMapper<CustomizedOrderTouristPrice> {

    /**
     * 订单套餐列表
     * @param orderId
     * @return
     */
    @Select("SELECT id,package_id,package_name,main_data_id,`name` AS touristTypeName,people_num,single_price,age_begin,age_end \n" +
            "FROM t_customized_order_tourist_price\n" +
            "WHERE order_id = #{order_id} AND is_deleted = 0 ORDER BY sort")
    List<OrderTouristPriceDTO> queryListByPackage(@Param("order_id") Long orderId);

    /**
     * 套餐旅客类型
     */
    @Select("SELECT main_data_id,`name` AS touristTypeName,people_num,single_price,age_begin,age_end \n" +
            "FROM t_customized_order_tourist_price\n" +
            "WHERE order_id = #{order_id} AND package_id = #{package_id} AND is_deleted = 0")
    List<TouristTypeNum> queryTouristTypeList(@Param("order_id") Long orderId, @Param("package_id") Long packageId);

    /**
     * 更新套餐人数统计
     * @param orderId
     * @param userId
     * @return
     */
    @Update("UPDATE t_customized_order_tourist_price\n" +
            "SET people_num = people_num - 1,modified_id = #{user_id}\n" +
            "WHERE order_id = #{order_id} AND package_id = #{package_id} AND main_data_id = #{main_data_id} AND is_deleted = 0")
    Integer updateByOrder(@Param("order_id")Long orderId,@Param("package_id")Long packageId,@Param("main_data_id")Long mainDataId, @Param("user_id")Long userId);
}
